<!DOCTYPE html>
<html lang="en">
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8">
    <title>净值统计</title>
    <link href="layui/css/layui.css" rel="stylesheet">
    <script type="text/javascript" src="layui/layui.js"></script>
    <script src="layuimini/js/lay-config.js" charset="utf-8"></script>
</head>
<body>
<!--显示在表头的工具条-->
<script type="text/html" id="toolBar">
    <div style="float: left">
        <div class="layui-btn-group">
            <button class="layui-btn layui-btn-primary" id="btn-expand" lay-event="btn-expand">全部展开</button>
            <button class="layui-btn layui-btn-primary" id="btn-fold" lay-event="btn-fold">全部折叠</button>
        </div>
    </div>
</script>

<div>
    <div class="layui-input-inline">
        <label class="layui-form-label layui-bg-gray" style="width: 100px;text-align: center">统计日期</label>
        <input type="text" name="statisticsDate" lay-verify="required"
               autocomplete="off" placeholder="yyyy-MM-dd" class="layui-input" id="statisticsDates" style="width: 150px">
    </div>
    <div class="layui-inline layui-show-xs-block">
        <button class="layui-btn" lay-submit="" lay-event="search" lay-filter="search" id="statisticsButton">
            <i class="layui-icon">&#xe615;</i>统计
        </button>
        <button class="layui-btn" lay-submit="" id="statisticsButton2">
            <i class="layui-icon">&#xe615;</i>查询
        </button>
    </div>
</div>


<script type="text/javascript">
    //加载表格
    layui.use(['table', 'treetable', 'element', 'form', 'layer', 'laydate'], function(){
        var $ = layui.jquery;
        var table = layui.table;
        var treetable = layui.treetable;
        var layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;

        laydate.render({
            elem: '#statisticsDates'
        })

        // 渲染表格
        treetable.render({
            treeColIndex: 2,
            treeSpid: -1,
            treeIdName: 'projectId',
            treePidName: 'parentMenuId',
            elem: '#demo',
            toolbar: '#toolBar',//显示在表头的工具条
            url: 'valusStatisticalSelectDate?statisticsDate=2022-9-5',
            page: false,
            cols: [
                [
                    {type: 'checkbox',field: 'left'},
                    {field:'projectId', title: '功能编号', align: 'center', hide: true}
                    /*,{field:'parentMenuId', title: '父功能编号'}
                    ,{field:'fundCode', title: '基金代码', align: 'center'}*/
                    ,{field:'projectName', minWidth: 150, title: '项目名称'}
                    ,{field:'statisticalCode', width: 150, title: '项目代码', align: 'center'}
                    ,{field:'parValue', width: 150, title: '股数', align: 'center',templet: function (x) {
                        if(x.parValue==0){
                            return "";
                        }
                        else{
                            return fmoney(x.parValue,2);
                        }
                    }}
                    ,{field:'quotePrice', width: 150, title: '行情价格', align: 'center',templet: function (x) {
                        if(x.quotePrice==0){
                            return "";
                        }
                        else{
                            return fmoney(x.quotePrice,2);
                        }
                    }}
                    ,{field:'notValueCost', width: 150, title: '成本', align: 'center',templet: function (x) {
                        if(x.notValueCost==0){
                            return "";
                        }
                        else{
                            return fmoney(x.notValueCost,2);
                        }
                    }}
                    ,{field:'marketPrice', width: 150, title: '市值', align: 'center',templet: function (x) {
                        if(x.marketPrice==0){
                            return "";
                        }
                        else{
                            return fmoney(x.marketPrice,2);
                        }
                    }}
                    ,{field:'valuation', width: 150, title: '估值增值', align: 'center',templet: function (x) {
                        if(x.valuation==0){
                            return "";
                        }
                        else{
                            return fmoney(x.valuation,2);
                        }
                    }}
                ]
            ],
            done: function () {
                // layer.closeAll('loading');
            },
        });

        table.on('toolbar(munu-table)', function (obj) {
            switch (obj.event) {
                <!--展开按钮-->
                case 'btn-expand':
                    treetable.expandAll('#munu-table');
                    break;
                case 'btn-fold':
                    <!--折叠按钮-->
                    treetable.foldAll('#munu-table');
                    break;
            }
        });

        $('#statisticsButton2').click(function () {
            treetable.render({
                treeColIndex: 2,
                treeSpid: -1,
                treeIdName: 'projectId',
                treePidName: 'parentMenuId',
                elem: '#demo',
                toolbar: '#toolBar',//显示在表头的工具条
                url: 'valusStatisticalSelectDate?statisticsDate=' + $('#statisticsDates').val(),
                page: false,
                cols: [
                    [
                        {type: 'checkbox',field: 'left'},
                        {field:'projectId', title: '功能编号', align: 'center', hide: true}
                        /*,{field:'parentMenuId', title: '父功能编号'}
                        ,{field:'fundCode', title: '基金代码', align: 'center'}*/
                        ,{field:'projectName', minWidth: 150, title: '项目名称'}
                        ,{field:'statisticalCode', width: 150, title: '项目代码', align: 'center'}
                        ,{field:'parValue', width: 150, title: '股数', align: 'center',templet: function (x) {
                            if(x.parValue===0){
                                return "";
                            }
                            else{
                                return fmoney(x.parValue,2);
                            }
                        }}
                        ,{field:'quotePrice', width: 150, title: '行情价格', align: 'center',templet: function (x) {
                            if(x.quotePrice===0){
                                return "";
                            }
                            else{
                                return fmoney(x.quotePrice,2);
                            }
                        }}
                        ,{field:'notValueCost', width: 150, title: '成本', align: 'center',templet: function (x) {
                            if(x.notValueCost===0){
                                return "";
                            }
                            else{
                                return fmoney(x.notValueCost,2);
                            }
                        }}
                        ,{field:'marketPrice', width: 150, title: '市值', align: 'center',templet: function (x) {
                            if(x.marketPrice===0){
                                return "";
                            }
                            else{
                                return fmoney(x.marketPrice,2);
                            }
                        }}
                        ,{field:'valuation', width: 150, title: '估值增值', align: 'center',templet: function (x) {
                            if(x.valuation===0){
                                return "";
                            }
                            else{
                                return fmoney(x.valuation,2);
                            }
                        }}
                    ]
                ],
                done: function () {
                    // layer.closeAll('loading');
                },
            });
        })

        $('#statisticsButton').click(function () {
            treetable.render({
                treeColIndex: 2,
                treeSpid: -1,
                treeIdName: 'projectId',
                treePidName: 'parentMenuId',
                elem: '#demo',
                toolbar: '#toolBar',//显示在表头的工具条
                url: 'insertValusStatistical?statisticsDate=' + $('#statisticsDates').val(),
                page: false,
                cols: [
                    [
                        {type: 'checkbox',field: 'left'},
                        {field:'projectId', title: '功能编号', align: 'center', hide: true}
                        /*,{field:'parentMenuId', title: '父功能编号'}
                        ,{field:'fundCode', title: '基金代码', align: 'center'}*/
                        ,{field:'projectName', minWidth: 150, title: '项目名称'}
                        ,{field:'statisticalCode', width: 150, title: '项目代码', align: 'center'}
                        ,{field:'parValue', width: 150, title: '股数', align: 'center',templet: function (x) {
                            if(x.parValue===0){
                                return "";
                            }
                            else{
                                return fmoney(x.parValue,2);
                            }
                        }}
                        ,{field:'quotePrice', width: 150, title: '行情价格', align: 'center',templet: function (x) {
                            if(x.quotePrice===0){
                                return "";
                            }
                            else{
                                return fmoney(x.quotePrice,2);
                            }
                        }}
                        ,{field:'notValueCost', width: 150, title: '成本', align: 'center',templet: function (x) {
                            if(x.notValueCost===0){
                                return "";
                            }
                            else{
                                return fmoney(x.notValueCost,2);
                            }
                        }}
                        ,{field:'marketPrice', width: 150, title: '市值', align: 'center',templet: function (x) {
                            if(x.marketPrice===0){
                                return "";
                            }
                            else{
                                return fmoney(x.marketPrice,2);
                            }
                        }}
                        ,{field:'valuation', width: 150, title: '估值增值', align: 'center',templet: function (x) {
                            if(x.valuation===0){
                                return "";
                            }
                            else{
                                return fmoney(x.valuation,2);
                            }
                        }}
                    ]
                ],
                done: function () {
                    // layer.closeAll('loading');
                },
            });
        })


    });

    function fmoney(s, n) {

        n = n > 0 && n <= 20 ? n : 2;

        s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";

        var l = s.split(".")[0].split("").reverse(),

            r = s.split(".")[1];

        t = "";

        for(i = 0; i < l.length; i ++ )

        {

            t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");

        }

        return t.split("").reverse().join("") + "." + r;

    }
</script>
</body>
<table id="demo" lay-filter="demo"></table>
</html>